using System.Xml;

namespace RealDolmen.SharePoint.ListFeatures.Elements
{
    public class ListFeatureElementsFile
    {
        #region Fields
        private ListFeatureDefinition featdefParent;
        private string pathElementXml;
        internal const string m_tagElements = "Elements"; 
        #endregion // Fields

        #region Constructor
        internal ListFeatureElementsFile(ListFeatureDefinition featdefParent, string pathElementXml)
        {
            this.pathElementXml = pathElementXml;
            this.featdefParent = featdefParent;
        } 
        #endregion // Constructor

        #region Business Methods
        public XmlNodeList GetElementNodes()
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(FullPath);

            if (xmlDocument != null)
            {
                XmlNode documentElement = xmlDocument.DocumentElement;
                if (documentElement.Name == m_tagElements)
                {
                    return documentElement.ChildNodes;
                }
            }
            return null;
        } 
        #endregion // Business Methods

        #region Public Properties
        public string FullPath
        {
            get
            {
                return featdefParent.FeatureRelativeToAbsolutePath(this.pathElementXml);
            }
        } 
        #endregion // Public Properties
    }
}
